package com.hundsun.yr.universal.p2p.bean;

import android.content.Context;

import com.hundsun.mobile.zwgt.R;
import com.hundsun.yr.universal.library.utils.HsNumberUtils;

import java.io.Serializable;
import java.util.List;

/**
 * Created by xx on 2017/4/27.
 * LoanProductBeen--借款产品
 */
public class LoanProductBeen implements Serializable{
    /**
     * id : 1
     * name : 中网融
     * debt_min : 50000.00
     * debt_max : 200000.00
     * debt_step : 10000.00
     * raise_term : 1
     * pay_method : 1
     * review_term : 1
     * guarantee_flag : 0
     * pledge_flag : 0
     * trustee_flag : 0
     * prepayment_flag : 1
     * prepayment_begin : 10
     * prepayment_end : 10
     * purpose_list : "消费","经营","非证券类投资"
     * show_cost_flag : 1
     * remain_credit : 500000.00
     * rate_list : [{"id":"37","type_id":"1","term_min":"10","term_max":"90","debt_rate":"7.5000","discount_rate":"0.0000","service_fee":"5.5000","risk_fee":"0.0000","guarantee_fee":"0.0000","pledge_fee":"0.0000","prepayment_fee":"0.0000"},{"id":"39","type_id":"1","term_min":"91","term_max":"180","debt_rate":"8.0000","discount_rate":"0.0000","service_fee":"5.0000","risk_fee":"0.0000","guarantee_fee":"0.0000","pledge_fee":"0.0000","prepayment_fee":"0.0000"},{"id":"40","type_id":"1","term_min":"181","term_max":"360","debt_rate":"8.5000","discount_rate":"0.0000","service_fee":"4.5000","risk_fee":"0.0000","guarantee_fee":"0.0000","pledge_fee":"0.0000","prepayment_fee":"0.0000"}]
     */

    public String id;
    public String name;
    public String debt_min;
    public String debt_max;
    public String debt_step;
    public String raise_term;
    public String pay_method;
    public String review_term;
    public String guarantee_flag;
    public String pledge_flag;
    public String trustee_flag;
    public String prepayment_flag;
    public String prepayment_begin;
    public String prepayment_end;
    public String purpose_list;
    public String show_cost_flag;
    public String remain_credit;
    public List<RateListBean> rate_list;
    /**
     * corp_general_fdd_auth_id : 1
     * corp_general_fdd_contract_id : 2
     * general_fdd_auth_id : 1
     * general_fdd_contract_id : 2
     * protocol_name : 授权服务协议
     * protocol_url : https://zwgt-test.oss-cn-shanghai.aliyuncs.com/notice/1496219355000_pR8SHPQJaB.pdf
     */

    public String corp_general_fdd_auth_id;
    public String corp_general_fdd_contract_id;
    public String general_fdd_auth_id;
    public String general_fdd_contract_id;
    public String protocol_name;
    public String protocol_url;
    public String risk_msg;

    public static class RateListBean implements Serializable{
        /**
         * id : 37
         * type_id : 1
         * term_min : 10
         * term_max : 90
         * debt_rate : 7.5000
         * discount_rate : 0.0000
         * service_fee : 5.5000
         * risk_fee : 0.0000
         * guarantee_fee : 0.0000
         * pledge_fee : 0.0000
         * prepayment_fee : 0.0000
         */

        public String id;
        public String type_id;
        public String term_min;
        public String term_max;
        public String debt_rate;
        public String discount_rate;
        public String service_fee_show;
        public String risk_fee;
        public String guarantee_fee;
        public String pledge_fee;
        public String prepayment_fee;

        @Override
        public String toString() {
            return "RateListBean{" +
                    "id='" + id + '\'' +
                    ", type_id='" + type_id + '\'' +
                    ", term_min='" + term_min + '\'' +
                    ", term_max='" + term_max + '\'' +
                    ", debt_rate='" + debt_rate + '\'' +
                    ", discount_rate='" + discount_rate + '\'' +
                    ", service_fee='" + service_fee_show + '\'' +
                    ", risk_fee='" + risk_fee + '\'' +
                    ", guarantee_fee='" + guarantee_fee + '\'' +
                    ", pledge_fee='" + pledge_fee + '\'' +
                    ", prepayment_fee='" + prepayment_fee + '\'' +
                    '}';
        }
    }

    public String getPayMethod(Context mContext){
        String payMethod = "";
        switch (pay_method){
            case "1":
                payMethod = mContext.getString(R.string.debt_service_at_maturity);
                break;
            case "2":
                payMethod = mContext.getString(R.string.first_coupon_later_edition);
                break;
            case "3":
                payMethod = mContext.getString(R.string.monthly_equal_principal_and_interest);
                break;
            case "4":
                payMethod = mContext.getString(R.string.monthly_principal);
                break;
        }
        return payMethod;
    }

    @Override
    public String toString() {
        return "LoanProductBeen{" +
                "id='" + id + '\'' +
                ", name='" + name + '\'' +
                ", debt_min='" + debt_min + '\'' +
                ", debt_max='" + debt_max + '\'' +
                ", debt_step='" + debt_step + '\'' +
                ", raise_term='" + raise_term + '\'' +
                ", pay_method='" + pay_method + '\'' +
                ", review_term='" + review_term + '\'' +
                ", guarantee_flag='" + guarantee_flag + '\'' +
                ", pledge_flag='" + pledge_flag + '\'' +
                ", trustee_flag='" + trustee_flag + '\'' +
                ", prepayment_flag='" + prepayment_flag + '\'' +
                ", prepayment_begin='" + prepayment_begin + '\'' +
                ", prepayment_end='" + prepayment_end + '\'' +
                ", purpose_list='" + purpose_list + '\'' +
                ", show_cost_flag='" + show_cost_flag + '\'' +
                ", remain_credit='" + remain_credit + '\'' +
                ", rate_list=" + rate_list +
                '}';
    }

    /**
     * 获取投资期限单位
     * @param pay_method
     * @return
     */
    public static String getPayMethod2(String pay_method) {

        String limttype = "";

        switch (pay_method){
            case "1":
                limttype = " 天";
                break;
            default :
                limttype = " 月";
                break;
        }
        return limttype;
    }


    /**
     * 显示投资期限
     * @return
     */
    public String getTerm(){
        try{
            String duration= HsNumberUtils.numberFormat("##0", rate_list.get(rate_list.size() - 1).term_max)+getPayMethod2(pay_method);
            return duration;
        } catch (Exception e){
            return "";
        }
    }
}
